package cn.yitun.chat.yitunserverrunsingleboot.chat.common.box;

import cn.yitun.chat.yitunactiondispatch.extend.ActionBox;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * 获取springbean的工具类
 * Date 2019-01-12 22:19:52<br>
 * Description
 * @author yitun
 * @since 1.1
 */

public class HandlerActionBox implements ActionBox, ApplicationContextAware {

	private ApplicationContext applicationContext = null;

	/**
	 * 获取执行器
	 * @param type
	 * @return
	 */
	@Override
	public Object getAction(Class<?> type) {

		Object o = null;
		if (null != applicationContext) {
			o = applicationContext.getBean(type);
		}
		return o;
	}
	/**
	 * 获取执行器
	 * @param className
	 * @return
	 */
	@Override
	public Object getAction(String className) {
		Object o = null;
		if (null != applicationContext) {
			o = applicationContext.getBean(className);
		}
		return o;
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.applicationContext = applicationContext;
	}
}
